package com.basker.pisces.core.query;

import java.util.List;

import com.basker.pisces.core.PageRowList;
import com.basker.pisces.core.RowContract;

/**
 * 查询器接口
 *
 * @author hangwen
 */
public interface IQuery {

    /**
     * 分页查询
     *
     * @param queryInfo
     * @param pagingInfo
     * @return
     */
    PageRowList queryForPageRows(QueryInfo queryInfo, PagingInfo pagingInfo);

    /**
     * 根据查询器的内容，从数据库查询结果的数量
     *
     * @param queryInfo 查询信息
     * @return
     */
    int queryForRowCount(QueryInfo queryInfo);

    /**
     * 列表查询
     *
     * @param queryInfo
     * @return
     */
    List<RowContract> queryForRows(QueryInfo queryInfo);

    /**
     * 分页信息
     *
     * @author hangwen
     */
    public static class PagingInfo {
        public static final int FIRST_PAGE_INDEX = 1;

        public static final PagingInfo NO_PAGING = new PagingInfo(-1, -1) {
            @Override
            public boolean isPagingQuery() {
                return false;
            }
        };

        public static PagingInfo getNoPaging() {
            return NO_PAGING;
        }

        private Integer pageIndex;

        private Integer pageSize;

        public PagingInfo(Integer pageIndex, Integer pageSize) {
            this.pageIndex = pageIndex;
            this.pageSize = pageSize;
        }

        public Integer getPageIndex() {
            return pageIndex;
        }

        public Integer getPageSize() {
            return pageSize;
        }

        public boolean isPagingQuery() {
            return this.pageIndex != null && this.pageIndex >= 0 && this.pageSize != null && this.pageSize > 0;
        }
    }

}
